﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;

namespace WindowsFormsApplication2.Model
{
    class LayananCabang
    {

        int id;
        int id_layanan;
        int id_cabang;
        int harga;
        int komisi;

        public LayananCabang()
        {

        }

        public LayananCabang(int _Id_Layanan)
        {
            Database db = new Database();
            DataSet ds = new DataSet();
            DataTable dt = new DataTable();
            string sql = "SELECT * FROM layanan_x_cabang WHERE nama = '" + _Id_Layanan + "'";

            db.Open();
            ds = db.ExecuteQuery(sql);
            dt = ds.Tables[0];
            DataRow dr = dt.Rows[0];

            id = (int)dr[0];
            id_layanan = (int)dr[1];
            id_cabang = (int)dr[2];
            harga = (int)dr[3]; ;
            komisi = (int)dr[4];
            db.Close();
        }

        public static ArrayList daftarLayananCabang(int _Id_Cabang)
        {
            ArrayList a = new ArrayList();
            Database db = new Database();
            DataSet ds = new DataSet();
            DataTable dt = new DataTable();
            object[] o = new object[4];
            string sql = "SELECT layanan_x_cabang.id, layanan.id, nama, harga FROM layanan INNER JOIN layanan_x_cabang ON (layanan.id = layanan_x_cabang.id_layanan) WHERE id_cabang = " + _Id_Cabang;

            db.Open();
            ds = db.ExecuteQuery(sql);
            db.Close();
            dt = ds.Tables[0];
            DataRow dr;

            for (int i = 0; i < dt.Rows.Count; ++i)
            {
                dr = dt.Rows[i];

                o[0] = (int)dr[0];
                o[1] = (string)dr[1];
                o[2] = (string)dr[2];
                o[3] = (int)dr[3];
                a.Add(o.Clone());
            }

            return a;
        }

        public void addLayananCabang()
        {
            Database db = new Database();
            string sql = "INSERT INTO layanan_x_cabang(id_layanan, id_cabang, harga, komisi) VALUES ('" + id_layanan.ToString() + "','" + id_cabang.ToString() + "','" + harga.ToString() + "','" + komisi.ToString() + "')";
            db.Open();
            db.ExecuteNonQuery(sql);
            db.Close();

        }

        public void updateLayananCabang()
        {
        }

        public void deleteLayananCabang()
        {
        }

    }
}
